﻿#include "widget.h"
#include "ui_widget.h"

Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);

    //treeWidget树控件的使用
    //设置水平头
    ui->treeWidget->setHeaderLabels(QStringList() << "诗名" << "内容" );

    QTreeWidgetItem *l1 = new QTreeWidgetItem(QStringList()<<"唐代");
    QTreeWidgetItem *l2 = new QTreeWidgetItem(QStringList()<<"宋代");
    QTreeWidgetItem *l3 = new QTreeWidgetItem(QStringList()<<"明代");

    //加载顶层节点
    ui->treeWidget->addTopLevelItem(l1);
    ui->treeWidget->addTopLevelItem(l2);
    ui->treeWidget->addTopLevelItem(l3);

    //追加子节点
    QStringList poem1;
    poem1<<"春晓"<<"春眠不觉晓，处处闻啼鸟，夜来风雨声，花落知多少。";
    QTreeWidgetItem *l4 = new QTreeWidgetItem(poem1);
    l1->addChild(l4);
}

Widget::~Widget()
{
    delete ui;
}

